import path from 'node:path'
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import serve from 'koa-static'
import { createRoutes } from '../router/index'
import { cors } from '../middleware/cors.middleware'
import { log4jsToCtx, logger } from '../middleware/logger.middleware'

const app = new Koa()

app.use(log4jsToCtx)
app.use(logger)
app.use(cors)
app.use(serve(path.join(__dirname, '..', '..', './public')))
app.use(bodyParser())
createRoutes(app)
app.on('error', (err) => {
  console.log('应用错误:', err)
})

export default app
